package com.suda.service.impl;

import com.suda.entity.User;
import com.suda.mapper.UserMapper;
import com.suda.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return this.userMapper.findAll();
    }

    @Override
    @Transactional
    public void saveAll(List<User> users) {
        users.forEach(user -> {
            user.setId(null);
            //只保存文件名称,现在保存的是完整的路径
            int startIndex = user.getPhoto().lastIndexOf("\\") + 1;
            user.setPhoto(user.getPhoto().substring(startIndex));
            this.userMapper.save(user);
        });
    }

}
